define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/order/index' + location.search,
                    // add_url: 'product/order/add',
                    // edit_url: 'product/order/edit',
                    // del_url: 'product/order/del',
                    // multi_url: 'product/order/multi',
                    import_url: 'product/order/import',
                    table: 'product_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'orderid', title: __('Orderid'), operate: 'LIKE'},
                        {field: 'total', title: __('Total'), operate: 'BETWEEN'},
                        // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'transfee', title: __('Transfee'), operate: 'BETWEEN'},
                        {field: 'all', title: __('All'), operate: 'BETWEEN'},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "1": __('已支付'),
                                "5": __('待结算'),
                                "6": __('待发货'),
                                "10": __('已发货'),
                                "20": __('已完成')
                            },
                            formatter: Table.api.formatter.status
                        },
                        // {field: 'user_id', title: __('User_id')},
                        {
                            field: 'paytype',
                            title: __('Paytype'),
                            searchList: {"1": __('报单币'), "6": __('商城币')},
                            formatter: Table.api.formatter.status
                        },
                        // {field: 'addressid', title: __('Addressid')},
                        {
                            field: 'is_trans',
                            title: __('Is_trans'),
                            searchList: {"1": __('是'), "0": __('否')},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'message', title: __('Message'), operate: 'LIKE'},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'pay_time',
                            title: __('Pay_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'send_time',
                            title: __('Send_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'finish_time',
                            title: __('Finish_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },

                        // {field: 'listo.id', title: __('Listo.id')},
                        // {field: 'listo.product_id', title: __('Listo.product_id')},
                        // {field: 'listo.product_name', title: __('Listo.product_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'listo.num', title: __('Listo.num')},
                        // {field: 'listo.order_id', title: __('Listo.order_id')},
                        // {field: 'listo.user_id', title: __('Listo.user_id')},
                        // {field: 'listo.price', title: __('Listo.price'), operate:'BETWEEN'},
                        // {field: 'listo.parameters', title: __('Listo.parameters'), operate: 'LIKE'},
                        // {field: 'listo.sku_id', title: __('Listo.sku_id')},
                        // {field: 'listo.iscomment', title: __('Listo.iscomment'), operate: 'LIKE'},
                        // {field: 'listo.total', title: __('Listo.total'), operate:'BETWEEN'},
                        // {field: 'listo.tag', title: __('Listo.tag'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        // {field: 'listo.toolid', title: __('Listo.toolid'), operate: 'LIKE'},
                        // {field: 'listo.tool', title: __('Listo.tool'), operate: 'LIKE'},
                        // {field: 'listo.send_name', title: __('Listo.send_name'), operate: 'LIKE'},
                        // {field: 'listo.send_contact', title: __('Listo.send_contact'), operate: 'LIKE'},
                        // {field: 'listo.send_address', title: __('Listo.send_address'), operate: 'LIKE'},
                        // {field: 'listo.createtime', title: __('Listo.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'listo.updatetime', title: __('Listo.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'listo.pay_time', title: __('Listo.pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'listo.send_time', title: __('Listo.send_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'listo.finish_time', title: __('Listo.finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'listo.status', title: __('Listo.status')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'listo',
                                    text: __('购物清单'),
                                    title: __('购物清单'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    // icon: 'fa fa-angellist',
                                    url: 'product/Listo/index?order_id={id}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'transport',
                                    text: __('收货地址'),
                                    title: __('收货地址'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    // icon: 'fa fa-angellist',
                                    url: 'Transport/index?address_id={addressid}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.is_trans == 1) {
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
